#! python
# -*- coding: utf-8 -*-
body = u"""
<entry xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearch/1.1/' xmlns:sites='http://schemas.google.com/sites/2008' xmlns:gs='http://schemas.google.com/spreadsheets/2006' xmlns:dc='http://purl.org/dc/terms' xmlns:batch='http://schemas.google.com/gdata/batch' xmlns:gd='http://schemas.google.com/g/2005' xmlns:thr='http://purl.org/syndication/thread/1.0' gd:etag='&quot;Wyl7ImA4&quot;'>
  <category scheme='http://schemas.google.com/g/2005#kind' term='http://schemas.google.com/sites/2008#webpage' label='webpage'/>
  <link rel='http://schemas.google.com/sites/2008#parent' type='application/atom+xml' href='http://sites.google.com/feeds/content/site/cedutd3/1470293887252443772'/>
  <title>new_user</title>
  <content type='xhtml'>
    <div xmlns="http://www.w3.org/1999/xhtml">
      <table cellspacing="0" class="sites-layout-name-one-column sites-layout-hbox">
	<tbody>
	  <tr>
	    <td class="sites-layout-tile sites-tile-name-content-1">
	      <div dir="ltr">
		<img src="http://www.google.com/chart?chc=sites&amp;cht=d&amp;chdp=sites&amp;chl=%5B%5BGoogle+Gadget%27%3D16%27f%5Cbf%5Chv%27a%5C%3D83%270%27%3D82%270%27dim%27%5Cbox1%27b%5CDBD9BB%27fC%5CDBD9BB%27eC%5C15%27sk%27%5C%5B%22Google+Clock%22%27%5Dh%27a%5CV%5C%3D12%27f%5Cbf%5C%5DV%5Cta%5C%3D84%27%3D0%27%3D83%27%3D167%27dim%27%5C%3D84%27%3D0%27%3D83%27%3D167%27vdim%27%5Cbox1%27b%5Cva%5CFFFEF0%27fC%5CDBD9BB%27eC%5Csites_gadget%27i%5Chv-0-0%27a%5C%5Do%5CLauto%27f%5C&amp;sig=pR5YynbRbM6UaxmkgaivViizD1U" igsrc="http://1.gmodules.com/ig/ifr?mid=1&amp;synd=trogedit&amp;url=http%3A%2F%2Fwww.matt.org%2Fmodules%2FGoogleClock.xml&amp;up_vsize=150px&amp;h=170&amp;w=170" type="ggs-gadget" props="spec:http#58//www.matt.org/modules/GoogleClock.xml;wrap:true;align:right;width:170;borderTitle:Google Clock;showBorder:false;igsrc:http#58//1.gmodules.com/ig/ifr?mid=1&amp;synd=trogedit&amp;url=http%3A%2F%2Fwww.matt.org%2Fmodules%2FGoogleClock.xml&amp;up_vsize=150px&amp;h=170&amp;w=170;height:170;scrolling:no;up_vsize:150px;showBorderTitle:null;mid:1;" width="170" height="170" style="display:inline;float:right;margin:5px 0 5px 20px;" class="igm" />
		<h2>
		  <a name="TOC-Easy-Steps" />
		  <i>
		    Easy Steps</i>
		</h2>
		<div>Welcome. This is your TD3 page. To get started, try the four steps that follow. Once you're comfortable, you can edit this page and remove these instructions.</div>
		<div> </div>
		<b>Step 1</b>: Change the title of this page from your email address to your name.<br />
		<ol style="list-style-type:lower-alpha">
		  <li>Click the "Edit page" button up above the page. These instructions will remain visible. <i>The page editing controls appear, buttons and menus much like those of any other editor.</i>
		  </li>
		  <li>Edit the title line to display your first and last name instead of your email address.</li>
		  <li>Click the "Save" button up above the page. <i>The page editing controls disappear.</i>
		  </li>
		</ol>
		So that's how you edit a page on our web site. You can edit any page, and should, when you can correct or improve something.<br />
		<br />
		<b>Step 2</b>: For practice, leave a comment on this page, then remove it. 
		<div>
		  <ol style="list-style-type:lower-alpha">
		    <li>Click "Comments" near the bottom of the page. <i>A box appears.</i>
		    </li>
		    <li>Type something into the box, then click the "Add comment" button. <i>Your comment is posted.</i>
		    </li>
		    <li>Click "Remove". <i>Your comment is removed.</i>
		    </li>
		  </ol>
		  <img src="http://www.google.com/chart?chc=sites&amp;cht=d&amp;chdp=sites&amp;chl=%5B%5BGoogle+Gadget%27%3D16%27f%5Cbf%5Chv%27a%5C%3D123%270%27%3D122%270%27dim%27%5Cbox1%27b%5CDBD9BB%27fC%5CDBD9BB%27eC%5C15%27sk%27%5C%5B%22Wikipedia+Search%22%27%5Dh%27a%5CV%5C%3D12%27f%5Cbf%5C%5DV%5Cta%5C%3D124%27%3D0%27%3D123%27%3D167%27dim%27%5C%3D124%27%3D0%27%3D123%27%3D167%27vdim%27%5Cbox1%27b%5Cva%5CFFFEF0%27fC%5CDBD9BB%27eC%5Csites_gadget%27i%5Chv-0-0%27a%5C%5Do%5CLauto%27f%5C&amp;sig=tBrGjh3r7wJGXwpKU8XVCe4pLLk" igsrc="http://235.gmodules.com/ig/ifr?mid=235&amp;synd=trogedit&amp;url=http%3A%2F%2Fwww.labpixies.com%2Fcampaigns%2Fwiki%2Fwiki.xml&amp;up_language=en&amp;up_source=wikipedia&amp;up_last_searches=none&amp;h=170&amp;w=250" type="ggs-gadget" props="spec:http#58//www.labpixies.com/campaigns/wiki/wiki.xml;wrap:true;up_last_searches:none;width:250;align:right;up_language:en;showBorder:true;borderTitle:Wikipedia Search;up_source:wikipedia;igsrc:http#58//235.gmodules.com/ig/ifr?mid=235&amp;synd=trogedit&amp;url=http%3A%2F%2Fwww.labpixies.com%2Fcampaigns%2Fwiki%2Fwiki.xml&amp;up_language=en&amp;up_source=wikipedia&amp;up_last_searches=none&amp;h=170&amp;w=250;height:170;scrolling:no;showBorderTitle:true;mid:235;" width="250" height="170" style="display:inline;float:right;margin:5px 0 5px 20px;" class="igm" />
		  <div>That's how you leave a comment on a page, when you have something to contribute but it doesn't merit editing the page.</div>
		  <div>
		    <br />
		  </div>
		  <div>If you'd like to, practice attaching a file and removing it. Click "Attachments" near the bottom of the page.</div>
		  <div>
		    <br />
		  </div>
		  <div>
		    <b>Step 3</b>: Find your district page then find your way back here.</div>
		  <div>
		    <br />
		  </div>
		  <div>This step takes you on a quick trip away from your page and back. Since the instructions won't be visible while you're gone, read them through before you go.</div>
		  <div>
		    <br />
		  </div>
		  <div>The sidebar on this and every page includes links to key pages in the web site. Near the top of the list you can see "Districts" and near the bottom "Your Page".</div>
		  <div>
		    <ol>
		      <li>Click "Districts" in the sidebar. <i>The districts overview page appears.</i>
		      </li>
		      <li>In the <b>District Pages</b> list, click the name of your district. <i>Your district page appears.</i>
		      </li>
		      <li>In the sidebar, click "Your Page". <i>This page reappears.</i>
		      </li>
		    </ol>
		    <div>Did you make it back? Way to go! You'll never be lost again.</div>
		    <div>
		      <br />
		    </div>
		    <div>Time to go to work.</div>
		    <div>
		      <br />
		    </div>
		    <div>
		      <b>Step 4</b>: Join a working group.<br />
		      <br />
		      In the sidebar, click on <b>Working Groups</b>. Find a working group that you will contribute to and join it.<br />
		      <br />
		      Good luck!<br />
		    </div>
		  </div>
		</div>
	      </div>
	    </td>
	  </tr>
	</tbody>
      </table>
    </div>
  </content>
  <sites:pageName>new_page</sites:pageName>
</entry>
""".encode('utf-8')

posted_entry = ""
addrs = ['sbremer@belchertown.org', 'cvigneux@belchertown.org', 'kroach@belchertown.org', 'skeegan@belchertown.org', 'anapolitano@belchertown.org', 'jcroft@eagle.fcts.org', 'jdoppler@grsd.org', 'mespinola@gmrsd.org', 'pdipietro@hadleyschools.org', 'kboyden@hadleyschools.org', 'tryan@hr-k12.org', 'rpool@hr-k12.org', 'bdornbusch@northampton.k12.ma.us', 'gravina@leverettschool.org', 'tech@swiftriverschool.org', 'csweklo@shschools.com', 'dobrien@shschools.com', 'galenski@erving.com', 'jchapin@hatfieldps.net', 'slaughterd@arps.org', 'jchamp@arps.org', 'moorer@arps.org', 'schottj@easthampton.k12.ma.us', 'follansbeen@easthampton.k12.ma.us', 'lawl@frsu38.deerfield.ma.us', 'rnash@frsu38.deerfield.ma.us', 'gervaiss@frsu38.deerfield.ma.us', 'dlukaskiewicz@granbyschoolsma.net', 'mduffy@hadleyschools.org', 'kboyden@hadleyschools.org', 'pduval@hatfieldps.net', 'sgoldman@hatfieldps.net', 'eskutnik@mohawkschools.org', 'mb@mohawkschools.org', 'rhaigh@orange-elem.org', 'doirond@pioneervalley.k12.ma.us', 'mahaneyt@pioneervalley.k12.ma.us', 'mleyden@mac.com', 'nowickij@pioneervalley.k12.ma.us', 'srokad@svahs.net', 'vmiller@winchendonk12.org', 'mcusack@mohawkschools.org', 'lyont@svahs.net', 'fabina@svahs.net']

authValue = "GoogleLogin auth=" "DQAAAIwAAADEYhxzVRZf6__Plzqjc0K1MjRAb1-eT9zIfANzNO5yCKr1Osm_hBzMpnSofjBp95Fq0pBwctt2o1J3uVB0hHmvXjxennnuiRTq-mVOlRwdx1HhdDMzRvecUPOJjoxk1savHDB_kjW1HuJyK8_1BUEWzIpzL9XAsE2VJ7HPOLFObPkTZW9ERDk0X_OIpssdAHA"
post_headers = {"Authorization" : authValue, "GData-Version" : "1.0", "Content-Type" : "application/atom+xml"}

import httplib
import re

def pp(email_addr):
  send_body = body.replace('new_user', email_addr)
  page_name = re.sub(r'[^a-z0-9]', '-', email_addr.lower())
  send_body = send_body.replace('new_page', page_name)
  conn = httplib.HTTPConnection("sites.google.com", timeout = 12)
  conn.set_debuglevel(1)
  conn.request('POST', '/feeds/content/site/cedutd3', send_body, post_headers)
  resp = conn.getresponse()
  posted_entry = resp.read()
  return resp.status
